package com.zcn.io.web.controller;

import com.zcn.io.web.api.dto.DictDto;
import com.zcn.io.web.service.AgencyService;
import com.zcn.io.common.entity.Agency;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.zcn.io.common.pojo.CommonResult;

import java.util.List;

/**
 * @desc:
 * @author: 202438 邱建伟
 * @date: 2024/9/20 22:27
 * @Copyright (c) 2024, 江苏金恒信息科技股份有限公司
 */
@RestController
@RequestMapping("/agency")
public class AgencyController {

    @Autowired
    private AgencyService agencyService;

    @GetMapping("/list")
    public CommonResult<List<Agency>> list(Agency agency) {
        return CommonResult.success(agencyService.list(agency));
    }

    @PostMapping("/save")
    public CommonResult<Agency> save(@RequestBody Agency agency) {
        agencyService.save(agency);
        return CommonResult.success(agency);
    }

    @GetMapping("/getById")
    public CommonResult<Agency> getById(String id) {
        return CommonResult.success(agencyService.getById(id));
    }

    @PostMapping("/updateById")
    public CommonResult<Agency> updateById(@RequestBody Agency agency) {
        agencyService.updateById(agency);
        return CommonResult.success(agency);
    }

    @DeleteMapping("/deleteById")
    @PreAuthorize("hasAuthority('super_man')")
    public CommonResult<String> deleteById(String id) {
        agencyService.deleteById(id);
        return CommonResult.success(id);
    }

    @GetMapping("/dict")
    public CommonResult<List<DictDto>> dict() {
        return CommonResult.success(agencyService.dict());
    }

}
